package io.rocketman.transport.netty.channel;

import io.rocketman.transport.channel.ChannelConvertor;

import java.net.InetSocketAddress;

/**
 * @author He Peng
 * @create 2018-05-26 21:44
 * @update 2018-05-26 21:44
 * @updatedesc : 更新说明
 * @see
 */
public class NettyChannelConvertor implements ChannelConvertor<NettyChannel> {

    @Override
    public NettyChannel convert(Object ch) {
        io.netty.channel.Channel nChannel = (io.netty.channel.Channel) ch;
        return NettyChannel.builder()
                .channel(nChannel)
                .remoteAddress((InetSocketAddress) nChannel.remoteAddress())
                .localAddress((InetSocketAddress) nChannel.localAddress())
                .isClose(!nChannel.isOpen())
                .isOpen(nChannel.isOpen())
                .clientMetaData(null)
                .serverMetaData(null)
                .build();
    }
}
